package cn.book.book.ctrl;

import cn.book.book.domain.Author;
import cn.book.book.service.AuthorService;
import cn.book.book.vo.AjaxResult;
import cn.book.book.vo.Page;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author oldliu
 * @since 1.0
 */
@RestController
@RequestMapping("book")
@Slf4j
public class AuthorController {
    //private static Logger log= LoggerFactory.getLogger(AuthorController.class);

    @Autowired
    private AuthorService authorService;

    @PostMapping("list")
    public Page<Author> list(@RequestBody Author author) {
        if (log.isDebugEnabled())
            log.debug(author + ">>>>>>>>>>");
        return authorService.selectList(author.getPageNum(), author.getPageSize(), author);
    }
    @PostMapping("del")
    public AjaxResult batchDel(@RequestBody Long[]ids){
        this.authorService.batchDel(ids);
        return AjaxResult.success("成功删除了："+Arrays.toString(ids));
    }
    @PostMapping("add")
    public AjaxResult add(@RequestBody Author a){
        int add = this.authorService.add(a);
        return AjaxResult.toAjax(add);
    }
}
